package chongwo.cn.mediaplayerproject;

import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.BounceInterpolator;
import android.view.animation.Transformation;

public class CustomAnimator extends Animation{

    Camera camera = new Camera();
    int mWidth = 0;
    int mHeight = 0;
    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);
        Matrix matrix = t.getMatrix();
        camera.save();
        camera.rotateY(10 * interpolatedTime);
        camera.getMatrix(matrix);
        camera.restore();
        matrix.preTranslate(mWidth, mHeight);
        matrix.postTranslate(-mWidth, -mHeight);
    }

    @Override
    public void initialize(int width, int height, int parentWidth, int parentHeight) {
        super.initialize(width, height, parentWidth, parentHeight);
        setDuration(2000);
        setFillAfter(true);
        setInterpolator(new BounceInterpolator());
        mWidth = parentWidth / 2;
        mHeight = parentHeight / 2;
    }
}